package com.thf.controller.echarts;

import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.thf.model.EchartsOneModel;
import com.thf.model.ResultData;
import com.thf.service.EchartsOneExcelUploadService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class EchartsOneExcelUploadController {

    @Resource
    private EchartsOneExcelUploadService echartsOneExcelUploadService;
    @PostMapping("/echartOne/excelUpload")
    public String excelUpload(@RequestParam("file") MultipartFile file){
        String fileName = file.getOriginalFilename();
        String filePath = "d:/excelData/"+fileName;
        System.out.println("===================>"+filePath);
        List<EchartsOneModel> list = EasyExcel.read(filePath).head(EchartsOneModel.class).sheet().doReadSync();
        System.out.println(JSON.toJSONString(list));
        ResultData result = echartsOneExcelUploadService.insertAll(list);
        return JSON.toJSONString(result);
    }
}
